package com.aimee.util;

import java.io.File;
import java.util.Date;

import com.aimee.dao.LoginDAO;
import com.aimee.entity.User;

import jxl.CellType;
import jxl.DateCell;
import jxl.Sheet;
import jxl.Workbook;


public class ReadExcel {
  public static void importExcel(File file) {
//	  UserDao dao=new UserDao();
	  LoginDAO dao=new LoginDAO();
//	  File file=new File("users.xls");
	try {
		//打开excel文件
		Workbook book=Workbook.getWorkbook(file);
		//获得Excel的第一个sheet表
		Sheet sheet=(Sheet)book.getSheet(0);
		System.out.println("获得的Excel数据"+sheet);
		System.out.println("行数"+sheet.getRows());
		System.out.println("列数"+sheet.getColumns());
//		Date bir = null;
		for(int i=1;i<sheet.getRows();i++) {
			int classid=Integer.parseInt(sheet.getCell(0, i).getContents());
			String name=sheet.getCell(1, i).getContents();
			String pass=sheet.getCell(2, i).getContents();
			String phone=sheet.getCell(3, i).getContents();
			String sex=sheet.getCell(4, i).getContents();
//			if(sheet.getCell(4,i).getType()==CellType.DATE) {
//				DateCell dc=(DateCell)sheet.getCell(4,i);
//				bir=dc.getDate();
//			}
			System.out.println(classid+"--"+name+"--"+pass+"--"+phone+"--"+sex);
			//把数据封装成对象
//			User users=new User(id,name,pass,img,bir);
			User user=new User(classid,name,pass,phone,sex);
		    dao.add(user);
		}
	} catch (Exception e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	} 
}
}
